<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>呈报人维护客户付款账号和我司收款账号信息(资金流出-我司付款)</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div class="fieldset1 tabel_col clearFix">
            <div class="fieldBox col_100">
                <div class="sqPanel">
                    <div style="text-align: center;">
                        <font color="#FF0000"><h3>建议使用工商银行、农业银行、中国银行、建设银行、交通银行账户收款。城市商业银行和农村信用合作社，受地域限制易造成银行付款失败。</h3></font>
                    </div>
                    <div class="sqPanel_head inL">
                        <div class="btnsBox inLC">
                            <span id="cstAddBtn_1" class="sq-button sq-button-round" style="display: none;" onclick="cstAddInBtnEvent('')">添加</span>
                            <span id="chooseCstBankInfo" class="sq-button sq-button-round" style="display: none;" onclick="chooseCstBankInfo()">选择账户</span>
                        </div>
                        <span>客户收款账户</span>
                    </div>
                    <div class="sqPanel_body">
                        <div id="ligergrid_cstBank_1" class="sq-grid"></div>
                    </div>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="sqPanel">
                    <div class="sqPanel_head inL">
                        <div class="btnsBox inLC">
                            <span id="ourComAddBtn_1" class="sq-button sq-button-round" style="display: none;" onclick="ourComOutAddBtnEvent('')">添加</span>
                            <span id="ourComConfirmBtn" class="sq-button sq-button-round" style="display: none;" onclick="confirmStlBankInfo()">确认无误</span>
                        </div>
                        <span>我司付款账户</span>
                    </div>
                    <div class="sqPanel_body">
                        <div id="ligergrid_ourComBank_1" class="sq-grid"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var basePath = '<%=path%>';
    var cstBankGrid_1;//客户付款账号
    var ourComBankGrid_1;//我司收款账号
    var cstId = '${pay.cstId}';
    var editInto = '${editInto}';
    var editOut = '${editOut}';
    var _paySchId = '${paySchId}';//这里 结清详细页面已有
    var _confirm = '${confirm}';

    var l_hidden_2 = "l-hidden";
    var l_hidden_3 = "l-hidden";

    $(function () {
        if (editInto == '1') {
            $("#cstAddBtn_1").show();
            $("#chooseCstBankInfo").show();
            l_hidden_2 = "";
        }
        if (editOut == '1') {
            $("#ourComAddBtn_1").show();
            l_hidden_3 = "";
        }
        if (_confirm == '1') {
            $("#ourComConfirmBtn").show();
        }

        initCstBankGrid_1();
        initOurComBankGrid_1();

    });

    function cstAddInBtnEvent(id) {
        $.ligerDialog.open({
            width: 800,
            height: 400,
            title: '编辑客户收款账户',
            url: basePath + '/project/prjPrdPaySchBank/toAddDialogPage.do?bindType=2&paySchId=' + _paySchId + "&id=" + id
        });
    }

    // 选择客户退款账户
    function chooseCstBankInfo() {
        $.ligerDialog.SQopen({
            width: 950,
            height: 400,
            title: '选择客户收款账户',
            url: basePath + '/settle/bank/toChooseBank.do?cstId=' + cstId + '&paySchId=' + _paySchId,
            fixButtons: true
        });
    }

    function ourComOutAddBtnEvent(id) {
        var url = basePath + '/project/prjPrdPaySchBank/toAddDialogPage.do?bindType=3&paySchId=' + _paySchId + "&id=" + id;
        $.ligerDialog.open({
            width: 800,
            height: 400,
            title: '编辑我司付款账户',
            url: url
        });
    }

    //初始化客户收款账号信息
    function initCstBankGrid_1() {
        cstBankGrid_1 = $("#ligergrid_cstBank_1").ligerGrid({
            url: basePath + '/project/prjPrdPaySchBank/initList.do',
            method: 'get',
            parms: {
                paySchId: _paySchId,
                fundFlowCd: ProjectConstant.CODE_PAY_SCH_FUND_FLOW_CD_OUT,
                fundTypCd: ProjectConstant.CODE_PAY_SCH_FUND_TYP_CD_INTO,
            },
            columns: [
                {display: '收款银行', name: 'bankNm', width: 120},
                {display: '收款账户', name: 'accNm', width: 120},
                {display: '收款账号', name: 'accNo', width: 180},
                {display: '开户行行号', name: 'bankNo', width: 120},
                {display: '开户行支行', name: 'branchBank', width: 180},
                {display: '预留手机号', name: 'actTel', width: 100},
                {display: '证件号码', name: 'identityNo', width: 140},
                {display: '备注', name: 'bankRem', minWidth: 150, editor: {type: 'text'}},
                {
                    display: '操作', width: 120, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var d = "";
                        if (rowdata.cstBankId == null || rowdata.cstBankId == undefined) {
                            d += '<a class="sq-button-hasicon ' + l_hidden_2 + '" href="javascript:cstAddInBtnEvent(' + rowdata.id + ')"><i class="sqBtnIco_4"></i>编辑</a>';
                        }
                        d += '<a class="sq-button-hasicon '+l_hidden_2+'" href="javascript:deleteBankInfoDB(' + rowdata.id + ',' + 2 + ')"><i class="sqBtnIco_7"></i>删除</a>';
                        return d;
                    }
                }
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 200,
            heightDiff: -2,
            enabledEdit: false,
            isScroll: true,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            enabledSort: false
        });
    }

    //初始化我司付款账号信息
    function initOurComBankGrid_1() {
        ourComBankGrid_1 = $("#ligergrid_ourComBank_1").ligerGrid({
            url: basePath + '/project/prjPrdPaySchBank/initList.do',
            method: 'get',
            parms:{
                paySchId:_paySchId,
                fundFlowCd:ProjectConstant.CODE_PAY_SCH_FUND_FLOW_CD_OUT,
                fundTypCd:ProjectConstant.CODE_PAY_SCH_FUND_TYP_CD_OUT,
            },
            columns: [
                {display: '付款银行', name: 'bankNm', width: 220, editor: {type: 'text'}},
                {display: '付款账号', name: 'accNo', width: 180, editor: {type: 'text'}},
                {display: '付款金额', name: 'payAmtDouble', width: 150, type: 'text',align: 'right',
                    render: function (rowdata, index, value) {
                        return StringUtils.isEmpty(value) ? '' : FormatMoney(value, 2);
                    }
                },
                {
                    display: '付款时间', name: 'payTm', width: 150,
                    render: function (rowdata, index, value) {
                        if (StringUtils.isEmpty(value)) return "";
                        var date = new Date(value);
                        return DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
                    }
                },
                {display: '备注', name: 'bankRem', minWidth: 140, editor: {type: 'text'}},
                {
                    display: '操作', width: 120, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var d = "";
                        d += '<a class="sq-button-hasicon ' + l_hidden_3 + '" href="javascript:ourComOutAddBtnEvent(' + rowdata.id + ')"><i class="sqBtnIco_4"></i>编辑</a>';
                        d += '<a class="sq-button-hasicon ' + l_hidden_3 + '" href="javascript:deleteBankInfoDB(' + rowdata.id + ',' + 3 + ')"><i class="sqBtnIco_7"></i>删除</a>';
                        return d;
                    }
                }
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 200,
            heightDiff: -2,
            enabledEdit: false,
            isScroll: true,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            enabledSort:false
        });
    }

    function deleteBankInfoDB(_id, _gridNm) {
        //删除数据库
        var _ids = [];
        _ids.push(_id);
        $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
            if (flag == false) return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {ids: JSON.stringify(_ids)},
                url: basePath + '/project/prjPrdPaySchBank/removeByIds.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        if (_gridNm == 1) {
                            cstBankGrid.reload();
                        } else if (_gridNm == 4) {
                            ourComBankGrid.reload();
                        } else if (_gridNm == 2) {
                            cstBankGrid_1.reload();
                        } else if (_gridNm == 3) {
                            ourComBankGrid_1.reload();
                        }
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

    function confirmStlBankInfo() {
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {
                paySchId: _paySchId,
                fundFlowCd: ProjectConstant.CODE_PAY_SCH_FUND_FLOW_CD_OUT,
                fundTypCd: ProjectConstant.CODE_PAY_SCH_FUND_TYP_CD_OUT,
            },
            url: basePath + '/settle/bank/confirmStlBankInfo.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

</script>

</body>
</html>
